<?php 
defined("_VALID_ACCESS") || die('Direct access forbidden');
class SCTV_ReportsCommon extends ModuleCommon {
    public static function menu() {
        return array(__('SCTV') => array('__submenu__' => 1, __('Reports') => array()));
    }
	public static function export_excel($report, $records)
	{
		set_time_limit(0);		
		
		$cols = array(
			array('name'=>__('Customer Group'), 'width'=>20),
			array('name'=>__('Customer Name'), 'width'=>30),
			array('name'=>__('Address'), 'width'=>10),
			array('name'=>__('Street'), 'width'=>25),
			array('name'=>__('Area'), 'width'=>15),
			array('name'=>__('Ward'), 'width'=>15),
			array('name'=>__('District'), 'width'=>15),				
			array('name'=>__('Phone'), 'width'=>15),
			array('name'=>__('Cable Status'), 'width'=>10),
            array('name'=>__('Main Analog'), 'width'=>10),
            array('name'=>__('Sub Analog'), 'width'=>10),
            array('name'=>__('Number Of HD'), 'width'=>10),
            array('name'=>__('Number Of SD'), 'width'=>10),
			array('name'=>__('Internet Package'), 'width'=>10),
			array('name'=>__('Bundle'), 'width'=>10),
			array('name'=>__('Counselor'), 'width'=>25),				
			array('name'=>__('Input Date'), 'width'=>15),
			array('name'=>__('Input Time'), 'width'=>10),
			array('name'=>__('Delivery Date'), 'width'=>15),
			array('name'=>__('Requirement Code'), 'width'=>10),
			array('name'=>__('Note'), 'width'=>30),
			array('name'=>__('Deployment Date'), 'width'=>15),
			array('name'=>__('Deployment Time'), 'width'=>10),
			array('name'=>__('Acceptance Date'), 'width'=>10),
			array('name'=>__('Deployment Employee'), 'width'=>30),
			array('name'=>__('Deployment Cable Status'), 'width'=>10),
            array('name'=>__('Deployment Main Analog'), 'width'=>10),
            array('name'=>__('Deployment Sub Analog'), 'width'=>10),
			array('name'=>__('Deployment HD'), 'width'=>10),
			array('name'=>__('Deployment SD'), 'width'=>10),
			array('name'=>__('Deployment Internet Package'), 'width'=>10),
			array('name'=>__('Deployment Bundle'), 'width'=>10),
			array('name'=>__('Deployment Business'), 'width'=>30),
			array('name'=>__('Cable Contract Code'), 'width'=>15),
			array('name'=>__('Internet Contract Code'), 'width'=>15),
			array('name'=>__('Customer Code'), 'width'=>15),
			array('name'=>__('Tap Code'), 'width'=>15),
			array('name'=>__('Lend Wifi'), 'width'=>15),
			array('name'=>__('Charge'), 'width'=>15),
			array('name'=>__('Secondary Counselor'), 'width'=>25),
            array('name'=>__('Secondary Main Analog'), 'width'=>10),
            array('name'=>__('Secondary Sub Analog'), 'width'=>10),
			array('name'=>__('Secondary HD'), 'width'=>10),
			array('name'=>__('Secondary SD'), 'width'=>10),
			array('name'=>__('Secondary Internet Package'), 'width'=>10)
		);
		
		
		require_once 'modules/Libs/PHPExcel/lib/PHPExcel.php';
		require_once 'modules/Libs/PHPExcel/lib/PHPExcel/Writer/Excel5.php';
		
		$objPHPExcel = new PHPExcel();
		
		$row = 1;$column = 0;
		$sheet = $objPHPExcel->getActiveSheet();
		
		foreach ($cols as $key=>$value){
			$sheet->getColumnDimensionByColumn($column)->setWidth($value['width']);
			
			$sheet->setCellValueByColumnAndRow($column, $row, $value['name']);
			
			$column++;
		}
		
		$tong_so_phieu_yeu_cau = 0;
		$tong_so_phieu_thc_yeu_cau = 0;
        $tong_so_phieu_main_analog_yeu_cau = 0;
        $tong_so_main_analog_yeu_cau = 0;
        $tong_so_phieu_sub_analog_yeu_cau = 0;
        $tong_so_sub_analog_yeu_cau = 0;
		$tong_so_phieu_hd_yeu_cau = 0;
		$tong_so_hd_yeu_cau = 0;	
		$tong_so_phieu_sd_yeu_cau = 0;
		$tong_so_sd_yeu_cau = 0;
		$tong_so_phieu_net_yeu_cau = 0;
		$tong_so_phieu_tron_goi_yeu_cau = 0;
		
		$tong_so_phieu_nghiem_thu = 0;
		$tong_so_phieu_thc_nghiem_thu = 0;
        $tong_so_phieu_main_analog_nghiem_thu = 0;
        $tong_so_main_analog_nghiem_thu = 0;
        $tong_so_phieu_sub_analog_nghiem_thu = 0;
        $tong_so_sub_analog_nghiem_thu = 0;
		$tong_so_phieu_hd_nghiem_thu = 0;
		$tong_so_hd_nghiem_thu = 0;	
		$tong_so_phieu_sd_nghiem_thu = 0;
		$tong_so_sd_nghiem_thu = 0;
		$tong_so_phieu_net_nghiem_thu = 0;
		$tong_so_phieu_tron_goi_nghiem_thu = 0;
								
		$internetpackages = array();
		$bundles = array();
		
		foreach ($records as $value) {
			$tong_so_phieu_yeu_cau++;

            $main_analog = $value['main_analog'];
            $sub_analog = $value['sub_analog'];
			$number_of_hd = $value['number_of_hd'];
			$number_of_sd = $value['number_of_sd'];
			if($number_of_hd > 0 || $number_of_sd > 0 || $main_analog > 0 || $sub_analog > 0)
			{
				$tong_so_phieu_thc_yeu_cau++;
                if($main_analog > 0) {
                    $tong_so_phieu_main_analog_yeu_cau++;
                    $tong_so_main_analog_yeu_cau += $main_analog;
                }
                if($sub_analog > 0) {
                    $tong_so_phieu_sub_analog_yeu_cau++;
                    $tong_so_sub_analog_yeu_cau += $sub_analog;
                }
				if($number_of_hd > 0)
				{
					$tong_so_phieu_hd_yeu_cau++;
					$tong_so_hd_yeu_cau += $number_of_hd;
				}
				if($number_of_sd > 0)
				{
					$tong_so_phieu_sd_yeu_cau++;
					$tong_so_sd_yeu_cau += $number_of_sd;
				}
			}
			
			$internet_package = $value['internet_package'];
			if($internet_package != '' && $internet_package != null)
			{
				$tong_so_phieu_net_yeu_cau++;
				
				if(array_key_exists($internet_package, $internetpackages))
					$internetpackages[$internet_package][0] = $internetpackages[$internet_package][0] + 1; 
				else
				{
					$internetpackages[$internet_package] = array(1, 0);					
				}
			}
			
			$bundle = $value['bundle'];
			if($bundle != '' && $bundle != null)
			{
				$tong_so_phieu_tron_goi_yeu_cau++;
				
				if(array_key_exists($bundle, $bundles))
					$bundles[$bundle][0] = $bundles[$bundle][0] + 1; 
				else
				{
					$bundles[$bundle] = array(1, 0);					
				}
			}
			
			$status = $value['status'];
			if($status == '1')
			{
				$tong_so_phieu_nghiem_thu++;

                $deployment_main_analog = $value['deployment_main_analog'];
                $deployment_sub_analog = $value['deployment_sub_analog'];
				$deployment_hd = $value['deployment_hd'];
				$deployment_sd = $value['deployment_sd'];
				if($deployment_hd > 0 || $deployment_sd > 0 || $deployment_main_analog > 0 || $deployment_sub_analog > 0)
				{
					$tong_so_phieu_thc_nghiem_thu++;
                    if($deployment_main_analog > 0) {
                        $tong_so_phieu_main_analog_nghiem_thu++;
                        $tong_so_main_analog_nghiem_thu += $deployment_main_analog;
                    }
                    if($deployment_sub_analog > 0) {
                        $tong_so_phieu_sub_analog_nghiem_thu++;
                        $tong_so_sub_analog_nghiem_thu += $deployment_sub_analog;
                    }
					if($deployment_hd > 0)
					{
						$tong_so_phieu_hd_nghiem_thu++;
						$tong_so_hd_nghiem_thu += $deployment_hd;
					}
					if($deployment_sd > 0)
					{
						$tong_so_phieu_sd_nghiem_thu++;
						$tong_so_sd_nghiem_thu += $deployment_sd;
					}
				}
				
				$internet_package = $value['deployment_internet_package'];
				if($internet_package != '' && $internet_package != null)
				{
					$tong_so_phieu_net_nghiem_thu++;
					
					if(array_key_exists($internet_package, $internetpackages))
						$internetpackages[$internet_package][1] = $internetpackages[$internet_package][1] + 1; 
					else
					{
						$internetpackages[$internet_package] = array(0, 1);					
					}
				}
			
				$bundle = $value['deployment_bundle'];
				if($bundle != '' && $bundle != null)
				{
					$tong_so_phieu_tron_goi_nghiem_thu++;
					
					if(array_key_exists($bundle, $bundles))
						$bundles[$bundle][1] = $bundles[$bundle][1] + 1; 
					else
					{
						$bundles[$bundle] = array(0, 1);					
					}
				}
			}

			$rec = array();
	
			$val = $value['customer_group'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['customer_name'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['address'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['street'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['area'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['ward'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['district'];
			$rec[] = SCTV_ReportsCommon::processing($val);					
			$val = $value['phone'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = SCTV_RequirementCommon::get_cable_status_name($value['cable_status']);
			$rec[] = SCTV_ReportsCommon::processing($val);
            $val = $value['main_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);
            $val = $value['sub_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['number_of_hd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['number_of_sd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['internet_package'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['bundle'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['counselor'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = date('d-m-Y', strtotime($value['input_date']));			
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['input_time'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['delivery_date'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['requirement_code'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['note'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_date'] == null?null:date('d-m-Y', strtotime($value['deployment_date']));
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_time'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['acceptance_date'] == null?null:date('d-m-Y', strtotime($value['acceptance_date']));
			$rec[] = SCTV_ReportsCommon::processing($val);
			
			$val = $value['deployment_employee'];
			$rec[] = SCTV_ReportsCommon::processing($val);
						
			$val = SCTV_RequirementCommon::get_cable_status_name($value['deployment_cable_status']);
			$rec[] = SCTV_ReportsCommon::processing($val);

            $val = $value['deployment_main_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);

            $val = $value['deployment_sub_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);

			$val = $value['deployment_hd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			
			$val = $value['deployment_sd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_internet_package'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_bundle'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_business'];
			$rec[] = SCTV_ReportsCommon::processing($val);			
			$val = $value['cable_contract_code'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['internet_contract_code'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['customer_code'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['tap_code'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = SCTV_RequirementCommon::get_lend_wifi_name($value['lend_wifi']);
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = Utils_CurrencyFieldCommon::format($value['charge']);
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['secondary_counselor'];
			$rec[] = SCTV_ReportsCommon::processing($val);
            $val = $value['secondary_main_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);
            $val = $value['secondary_sub_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['secondary_hd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['secondary_sd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['secondary_internet_package'];
			$rec[] = SCTV_ReportsCommon::processing($val);
						
			$row++;$column = 0;
		
			foreach ($rec as $value){			
				$sheet->setCellValueByColumnAndRow($column, $row, $value);			
				$column++;
			}
		}
	
		$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
		
		header('Content-Encoding: UTF-8');
		header('Content-type: text/xls; charset=UTF-8');
		header('Content-disposition: attachement; filename="'. $report .date('Y_m_d__H_i_s').'.xls"');
		$objWriter->save('php://output');
	}
	public static function export($report, $records)
	{
		set_time_limit(0);

		header('Content-Encoding: UTF-8');
		header('Content-type: text/csv; charset=UTF-8');
		header('Content-disposition: attachement; filename="'. $report .date('Y_m_d__H_i_s').'.csv"');
		if (headers_sent())
    		die('Some data has already been output to browser, can\'t send the file');

		$cols = array(
			__('Customer Group'),
			__('Customer Name'),
			__('Address'),
			__('Street'),
			__('Area'),
			__('Ward'),
			__('District'),				
			__('Phone'),
			__('Cable Status'),
            __('Main Analog'),
            __('Sub Analog'),
			__('Number Of HD'),
			__('Number Of SD'),
			__('Internet Package'),
			__('Bundle'),
			__('Counselor'),				
			__('Input Date'),
			__('Input Time'),
			__('Delivery Date'),
			__('Requirement Code'),
			__('Note'),
			__('Deployment Date'),
			__('Deployment Time'),
			__('Acceptance Date'),
			__('Deployment Employee'),
			__('Deployment Cable Status'),
            __('Deployment Main Analog'),
            __('Deployment Sub Analog'),
			__('Deployment HD'),
			__('Deployment SD'),
			__('Deployment Internet Package'),
			__('Deployment Bundle'),
			__('Deployment Business'),
			__('Cable Contract Code'),
			__('Internet Contract Code'),
			__('Customer Code'),
			__('Tap Code'),
			__('Lend Wifi'),
			__('Charge'),
			__('Secondary Counselor'),
            __('Secondary Main Analog'),
            __('Secondary Sub Analog'),
			__('Secondary HD'),
			__('Secondary SD'),
			__('Secondary Internet Package'));			

		$f = fopen('php://output','w');
		fwrite($f, "\xEF\xBB\xBF");
		fputcsv($f, $cols);

		$tong_so_phieu_yeu_cau = 0;
		$tong_so_phieu_thc_yeu_cau = 0;
        $tong_so_phieu_main_analog_yeu_cau = 0;
        $tong_so_main_analog_yeu_cau = 0;
        $tong_so_phieu_sub_analog_yeu_cau = 0;
        $tong_so_sub_analog_yeu_cau = 0;
		$tong_so_phieu_hd_yeu_cau = 0;
		$tong_so_hd_yeu_cau = 0;	
		$tong_so_phieu_sd_yeu_cau = 0;
		$tong_so_sd_yeu_cau = 0;
		$tong_so_phieu_net_yeu_cau = 0;
		$tong_so_phieu_tron_goi_yeu_cau = 0;
		
		$tong_so_phieu_nghiem_thu = 0;
		$tong_so_phieu_thc_nghiem_thu = 0;
        $tong_so_phieu_main_analog_nghiem_thu = 0;
        $tong_so_main_analog_nghiem_thu = 0;
        $tong_so_phieu_sub_analog_nghiem_thu = 0;
        $tong_so_sub_analog_nghiem_thu = 0;
		$tong_so_phieu_hd_nghiem_thu = 0;
		$tong_so_hd_nghiem_thu = 0;	
		$tong_so_phieu_sd_nghiem_thu = 0;
		$tong_so_sd_nghiem_thu = 0;
		$tong_so_phieu_net_nghiem_thu = 0;
		$tong_so_phieu_tron_goi_nghiem_thu = 0;
								
		$internetpackages = array();
		$bundles = array();
		
		foreach ($records as $value) {
			$tong_so_phieu_yeu_cau++;

            $main_analog = $value['main_analog'];
            $sub_analog = $value['sub_analog'];
			$number_of_hd = $value['number_of_hd'];
			$number_of_sd = $value['number_of_sd'];
			if($number_of_hd > 0 || $number_of_sd > 0 || $main_analog > 0 || $sub_analog > 0)
			{
				$tong_so_phieu_thc_yeu_cau++;
                if($main_analog > 0) {
                    $tong_so_phieu_main_analog_yeu_cau++;
                    $tong_so_main_analog_yeu_cau += $main_analog;
                }
                if($sub_analog > 0) {
                    $tong_so_phieu_sub_analog_yeu_cau++;
                    $tong_so_sub_analog_yeu_cau += $sub_analog;
                }
				if($number_of_hd > 0)
				{
					$tong_so_phieu_hd_yeu_cau++;
					$tong_so_hd_yeu_cau += $number_of_hd;
				}
				if($number_of_sd > 0)
				{
					$tong_so_phieu_sd_yeu_cau++;
					$tong_so_sd_yeu_cau += $number_of_sd;
				}
			}
			
			$internet_package = $value['internet_package'];
			if($internet_package != '' && $internet_package != null)
			{
				$tong_so_phieu_net_yeu_cau++;
				
				if(array_key_exists($internet_package, $internetpackages))
					$internetpackages[$internet_package][0] = $internetpackages[$internet_package][0] + 1; 
				else
				{
					$internetpackages[$internet_package] = array(1, 0);					
				}
			}
			
			$bundle = $value['bundle'];
			if($bundle != '' && $bundle != null)
			{
				$tong_so_phieu_tron_goi_yeu_cau++;
				
				if(array_key_exists($bundle, $bundles))
					$bundles[$bundle][0] = $bundles[$bundle][0] + 1; 
				else
				{
					$bundles[$bundle] = array(1, 0);					
				}
			}
			
			$status = $value['status'];
			if($status == '1')
			{
				$tong_so_phieu_nghiem_thu++;

                $deployment_main_analog = $value['deployment_main_analog'];
                $deployment_sub_analog = $value['deployment_sub_analog'];
				$deployment_hd = $value['deployment_hd'];
				$deployment_sd = $value['deployment_sd'];
				if($deployment_hd > 0 || $deployment_sd > 0 || $deployment_main_analog > 0 || $deployment_sub_analog > 0)
				{
					$tong_so_phieu_thc_nghiem_thu++;
                    if($deployment_main_analog > 0) {
                        $tong_so_phieu_main_analog_nghiem_thu++;
                        $tong_so_main_analog_nghiem_thu += $deployment_main_analog;
                    }
                    if($deployment_sub_analog > 0) {
                        $tong_so_phieu_sub_analog_nghiem_thu++;
                        $tong_so_sub_analog_nghiem_thu += $deployment_sub_analog;
                    }
					if($deployment_hd > 0)
					{
						$tong_so_phieu_hd_nghiem_thu++;
						$tong_so_hd_nghiem_thu += $deployment_hd;
					}
					if($deployment_sd > 0)
					{
						$tong_so_phieu_sd_nghiem_thu++;
						$tong_so_sd_nghiem_thu += $deployment_sd;
					}
				}
				
				$internet_package = $value['deployment_internet_package'];
				if($internet_package != '' && $internet_package != null)
				{
					$tong_so_phieu_net_nghiem_thu++;
					
					if(array_key_exists($internet_package, $internetpackages))
						$internetpackages[$internet_package][1] = $internetpackages[$internet_package][1] + 1; 
					else
					{
						$internetpackages[$internet_package] = array(0, 1);					
					}
				}
			
				$bundle = $value['deployment_bundle'];
				if($bundle != '' && $bundle != null)
				{
					$tong_so_phieu_tron_goi_nghiem_thu++;
					
					if(array_key_exists($bundle, $bundles))
						$bundles[$bundle][1] = $bundles[$bundle][1] + 1; 
					else
					{
						$bundles[$bundle] = array(0, 1);					
					}
				}
			}

			$rec = array();
	
			$val = $value['customer_group'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['customer_name'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['address'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['street'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['area'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['ward'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['district'];
			$rec[] = SCTV_ReportsCommon::processing($val);					
			$val = $value['phone'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = SCTV_RequirementCommon::get_cable_status_name($value['cable_status']);
			$rec[] = SCTV_ReportsCommon::processing($val);
            $val = $value['main_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);
            $val = $value['sub_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['number_of_hd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['number_of_sd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['internet_package'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['bundle'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['counselor'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = date('d-m-Y', strtotime($value['input_date']));			
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['input_time'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['delivery_date'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['requirement_code'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['note'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_date'] == null?null:date('d-m-Y', strtotime($value['deployment_date']));
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_time'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['acceptance_date'] == null?null:date('d-m-Y', strtotime($value['acceptance_date']));
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_employee'];
			$rec[] = SCTV_ReportsCommon::processing($val);			
			$val = SCTV_RequirementCommon::get_cable_status_name($value['deployment_cable_status']);
			$rec[] = SCTV_ReportsCommon::processing($val);
            $val = $value['deployment_main_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);
            $val = $value['deployment_sub_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_hd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_sd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_internet_package'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_bundle'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['deployment_business'];
			$rec[] = SCTV_ReportsCommon::processing($val);			
			$val = $value['cable_contract_code'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['internet_contract_code'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['customer_code'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['tap_code'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = SCTV_RequirementCommon::get_lend_wifi_name($value['lend_wifi']);
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = Utils_CurrencyFieldCommon::format($value['charge']);
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['secondary_counselor'];
			$rec[] = SCTV_ReportsCommon::processing($val);
            $val = $value['secondary_main_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);
            $val = $value['secondary_sub_analog'];
            $rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['secondary_hd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['secondary_sd'];
			$rec[] = SCTV_ReportsCommon::processing($val);
			$val = $value['secondary_internet_package'];
			$rec[] = SCTV_ReportsCommon::processing($val);
						
			fputcsv($f, $rec);
		}
		
		fputcsv($f, array());	
		$cols = array(
			__('Content'),
			__('Requirement'),
			__('Completed'));
			
		fputcsv($f, $cols);
		
		fputcsv($f, array('Tổng số phiếu', $tong_so_phieu_yeu_cau, $tong_so_phieu_nghiem_thu));
		fputcsv($f, array('Tổng số phiếu: THC', $tong_so_phieu_thc_yeu_cau, $tong_so_phieu_thc_nghiem_thu));
        fputcsv($f, array('  Số phiếu Analog điểm chính', $tong_so_phieu_main_analog_yeu_cau, $tong_so_phieu_main_analog_nghiem_thu));
        fputcsv($f, array('  Số đầu Analog điểm chính', $tong_so_main_analog_yeu_cau, $tong_so_main_analog_nghiem_thu));
        fputcsv($f, array('  Số phiếu Analog điểm phụ', $tong_so_phieu_sub_analog_yeu_cau, $tong_so_phieu_sub_analog_nghiem_thu));
        fputcsv($f, array('  Số đầu Analog điểm phụ', $tong_so_sub_analog_yeu_cau, $tong_so_sub_analog_nghiem_thu));
		fputcsv($f, array('  Số phiếu HD', $tong_so_phieu_hd_yeu_cau, $tong_so_phieu_hd_nghiem_thu));
		fputcsv($f, array('  Số đầu HD', $tong_so_hd_yeu_cau, $tong_so_hd_nghiem_thu));
		fputcsv($f, array('  Số phiếu SD', $tong_so_phieu_sd_yeu_cau, $tong_so_phieu_sd_nghiem_thu));
		fputcsv($f, array('  Số đấu SD', $tong_so_sd_yeu_cau, $tong_so_sd_nghiem_thu));
		fputcsv($f, array('Tổng số phiếu NET', $tong_so_phieu_net_yeu_cau, $tong_so_phieu_net_nghiem_thu));
		foreach ($internetpackages as $name => $values) {
			fputcsv($f, array('   ' . $name, $values[0], $values[1]));
		}
		
		fputcsv($f, array('Tổng số phiếu trọn gói', $tong_so_phieu_tron_goi_yeu_cau, $tong_so_phieu_tron_goi_nghiem_thu));
		foreach ($bundles as $name => $values) {
			fputcsv($f, array('   ' . $name, $values[0], $values[1]));
		}
	}
	public static function processing($val)
{
	$val = str_replace('&nbsp;',' ',htmlspecialchars_decode(strip_tags(preg_replace('/\<[Bb][Rr]\/?\>/',"\n",$val))));
	return trim($val);
}
} 
?>